<?php
/**
 * Author：晴天 QQ：1186258278
 * Creation：2020/3/19 18:09
 * Filename：kamun.php
 */

namespace extend;
class kamun extends Share
{
    /**
     * @param $data
     * 获取Cookie登陆信息
     */
    public static function LoginCookie($data)
    {
        if (file_exists(ROOT . 'includes/extend/log/Cookie/' . md5($data['url'] . $data['username']) . '.cookie') && $data['cache'] == 1) {
            $lock_dates = filemtime(ROOT . 'includes/extend/log/Cookie/' . md5($data['url'] . $data['username']) . '.cookie');
            $cookie = dirname(__FILE__) . '/log/Cookie/' . md5($data['url'] . $data['username']) . '.cookie';
            if ($lock_dates < (time() - 60 * 60 * 24)) {
                /**24H一次登陆*/
                $Curl_url = $data['url'] . 'index.php?m=Home&c=User&a=login';
                $Post_User = ['userName' => $data['username'], 'password' => $data['password'], 'loginTimes' => 1];
                $data = self::CurlCookieObtain($Curl_url, 0, $Post_User, $cookie);
                $data = json_decode($data, TRUE);
                if ($data['code'] <> 10000) {
                    @unlink($cookie);
                    return ['code' => -1, 'msg' => $data['mess']];
                }
            }
        } else {
            $cookie = dirname(__FILE__) . '/log/Cookie/' . md5($data['url'] . $data['username']) . '.cookie';
            $Curl_url = $data['url'] . 'frontLogin.htm?sendVerifyCode=0&jdfwkey=dwyyt';
            $Post_User = ['userName' => $data['username'], 'password' => $data['password'], 'loginTimes' => 1];
            $data = self::CurlCookieObtain($Curl_url, 0, $Post_User, $cookie);
            $data = json_decode($data, TRUE);
            if ($data['code'] <> 10000) {
                @unlink($cookie);
                return ['code' => -1, 'msg' => $data['mess']];
            }
        }

        return $cookie;
    }

    /**
     * @param $data 目录获取参数
     * 取商品目录
     */

    public static function Catalogue($data)
    {
        global $date, $times;

        if (file_exists(ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username']) . '.cache') && $data['cache'] == 1) {
            $lock_date = filemtime(ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username']) . '.cache');
            if (date("Y-m-d H:i:s", $lock_date) > $times) {
                $data = file_get_contents(ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username']) . '.cache');
                $data = json_decode($data, TRUE);
                return ['code' => 1, 'msg' => '商品目录数据获取成功！,共' . count($data) . '个商品目录！', 'date' => date("Y-m-d H:i:s", $lock_date), 'data' => $data];
            }
        }

        $Cookie = self::LoginCookie($data);
        if ($Cookie['code'] == -1) return $Cookie;
        $CurlHtml = $data['url'] . 'front/inter/dirList.htm';
        $HtmlData = self::CurlCookieObtain($CurlHtml, $Cookie);
        if ($HtmlData == '') return ['code' => -1, 'msg' => '卡易信目录数据获取失败,请重新尝试！'];

        $DataArr = self::CatalogueArray($HtmlData);
        if (count($DataArr) == 0) return ['code' => -1, 'msg' => '一个商品目录都没有！'];

        $datar = json_encode($DataArr, JSON_UNESCAPED_UNICODE);
        $filename = ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username']) . '.cache';
        fwrite(fopen($filename, "w"), $datar);

        return ['code' => 1, 'msg' => '商品目录数据获取成功！,共' . count($DataArr) . '个商品目录！', 'date' => $date, 'data' => $DataArr];

    }

    /**
     * @param $data
     * 根据目录取商品列表
     */
    public static function GoodsList($data)
    {
        global $date, $times;

        if (file_exists(ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username']) . '.cache') && $data['cache'] == 1) {
            $lock_date = filemtime(ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username'] . $data['dirId'] . $data['page']) . '.cache');
            if (date("Y-m-d H:i:s", $lock_date) > $times) {
                $data = file_get_contents(ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username'] . $data['dirId'] . $data['page']) . '.cache');
                $data = json_decode($data, TRUE);
                return ['code' => 1, 'msg' => '商品目录数据获取成功！,共' . count($data) . '个商品目录！', 'date' => date("Y-m-d H:i:s", $lock_date), 'data' => $data];
            }
        }

        $Cookie = self::LoginCookie($data);
        if ($Cookie['code'] == -1) return $Cookie;
        $PostData = ['nowPage' => $data['page'], 'dirId' => xiaochu_de($data['dirId']), 'keyWord' => '', 'dremId' => ''];
        $CurlHtml = $data['url'] . 'front/inter/cutPageGoodsList.htm';
        $HtmlData = self::CurlCookieObtain($CurlHtml, $Cookie, $PostData);
        if ($HtmlData == '') return ['code' => -1, 'msg' => '卡易信商品列表数据获取失败,请重新尝试！'];
        $GoodsListArray = self::GoodsListArray($data['url'], $HtmlData, xiaochu_de($data['dirId']));
        if (count($GoodsListArray) == 0) return ['code' => -1, 'msg' => '第' . $data['page'] . '页一个商品都没有！'];

        $filename = ROOT . 'includes/extend/log/Cache/' . md5($data['url'] . $data['username'] . $data['dirId'] . $data['page']) . '.cache';
        fwrite(fopen($filename, "w"), json_encode($GoodsListArray, JSON_UNESCAPED_UNICODE));
        return ['code' => 1, 'msg' => '第' . $data['page'] . '页商品列表获取成功！,共获取到' . count($GoodsListArray) . '个商品！', 'date' => $date, 'data' => $GoodsListArray];
    }


    /**
     * @param $data
     * 取出商品详情
     */
    public static function GoodsDetails($data)
    {
        $Cookie = self::LoginCookie($data);
        if ($Cookie['code'] == -1) return $Cookie;
        $CurlHtml = xiaochu_de($data['url_shop']);
        $HtmlData = self::CurlCookieObtain($CurlHtml, $Cookie);
        if ($HtmlData == '') return ['code' => -1, 'msg' => '卡易信商品列据获取失败,请重新尝试！'];
        return self::GoodsDetailsArray($HtmlData, xiaochu_de($data['url_shop']));
    }

    /**
     * @param $data
     * 取出商品余额
     */
    public static function Money($data)
    {
        $Cookie = self::LoginCookie($data);
        if ($Cookie['code'] == -1) return $Cookie;
        $CurlHtml = $data['url'] . 'front/inter/refreshmoney.htm';
        $HtmlData = self::CurlCookieObtain($CurlHtml, $Cookie);
        $money = json_decode($HtmlData, TRUE);
        if ($money['money'] == '') return ['code' => -1, 'msg' => '余额获取失败！'];
        return ['code' => 1, 'msg' => '余额获取成功,当前余额为：' . round($money['money'], 3) . '元！', 'money' => $money['money']];
    }

    /**
     * @param $data
     * 卡易信下单提交
     */
    public static function GoodsPurchased($data)
    {
        $Cookie = self::LoginCookie($data);
        if ($Cookie['code'] == -1) return $Cookie;
        $CurlHtml = $data['url'] . 'front/inter/uploadOrder.htm?salePwd=' . ($data['salePwd'] == '' ? '123123' : $data['salePwd']);
        $post = [
            'goodsId' => $data['goodsId'],
            'mainKey' => $data['mainKey'],
            'messinfo' => 'WX:xiaochu_web',
            'sumprice' => $data['sumprice'],
            'saleprice' => $data['saleprice'],
            'textAccountName' => $data['data']['value'][0],
        ];
        $post_value = [];
        for ($a = 1; $a < count($data['data']['value']); $a++) {
            if ($data['data']['value'][$a] == '' || $data['data']['value'][$a] == null) continue;
            $post_value = array_merge($post_value, [
                'temptypeName' . $a => ($data['data']['input'][$a] == '' ? '参数_' . ($a + 1) : $data['data']['input'][$a]),
                'lblName' . $a => $data['data']['value'][$a],
            ]);
        }
        $PostData = array_merge($post, $post_value);
        $data_goods = self::CurlGoodsPurchased($CurlHtml, $PostData, $Cookie, $data['goods_url']);
        $arr_data = json_decode($data_goods, TRUE);
        $url_moeny = $data['url'] . 'front/inter/refreshmoney.htm';
        if ($arr_data['mess'] == '') {
            return [
                'code' => -1,
                'msg' => '商品购买失败,请重新尝试'
            ];
        } else if ($arr_data['mess'] == '订单购买成功!') {
            $money = self::CurlCookieObtain($url_moeny, $Cookie);
            $money = json_decode($money, TRUE);
            return [
                'code' => 1,
                'msg' => $arr_data['mess'],
                'order' => $arr_data['orderNo'],
                'money' => ($money['money'] == '' ? 0 : $money['money'])
            ];
        } else if ($arr_data['mess'] == '账户余额不足!') {
            $money = self::CurlCookieObtain($url_moeny, $Cookie);
            $money = json_decode($money, TRUE);
            return [
                'code' => -1,
                'msg' => '账号余额不足,无法购买此商品!,当前账号余额为：' . ($money['money'] == '' ? 0 : $money['money']),
            ];
        } else if ($arr_data['mess'] == '交易密码错误!') {
            return [
                'code' => -1,
                'msg' => '交易密码错误,请前往后台配置!'
            ];
        } else {
            return [
                'code' => -1,
                'msg' => ($arr_data['mess'] == '' ? '未知异常！' : $arr_data['mess'])
            ];
        }
    }

    public static function OrderQuery($data)
    {
        $data['url_shop'] = xiaochu_de($data['url_shop']);
        $Cookie = self::LoginCookie($data);
        if ($Cookie['code'] == -1) return $Cookie;
        $CurlHtml = $data['url'] . 'front/inter/salelist.htm?inputKeyWord=' . $data['order'] . '&inputKeyValue=2&goodType=0&startTime=2009-11-10&endTime=2150-02-09&nowPage=1';
        $HtmlData = self::CurlCookieObtain($CurlHtml, $Cookie);
        if ($HtmlData == '') dies(-1, '查询失败');
        $arr_or = self::QuertId($HtmlData);
        if ($arr_or == '') {
            dies(-1, '查单ID获取失败');
        }
        $CurlHtml_or = $data['url'] . 'front/inter/showordermess.htm?orderid=' . $arr_or;
        $HtmlData_or = self::CurlCookieObtain($CurlHtml_or, $Cookie);
        if ($HtmlData_or == '') dies(-1, '查询失败');
        return self::QuertDataId($HtmlData_or);
    }

    /**
     * @param $data
     * 获取卡易信查单ID
     */
    public static function QuertId($data)
    {
        $reg1 = "/<tbody>.*?<\/tbody>/";
        $datam = str_replace(array("\r\n", "   ", "\r", "\n", "	"), "", $data);
        preg_match_all($reg1, $datam, $array_data);
        $reg2 = "/<td>.*?<\/td>/";
        preg_match_all($reg2, $array_data[0][0], $array_data2);
        foreach ($array_data2[0] as $v) {
            if (strpos($v, 'name="showorder"') !== false) {
                $arr = explode('id="', $v);
                $arr = explode('">', $arr[1]);
                return $arr[0];
            }
        }
    }

    /**
     * @param $data
     * 根据ID查询订单详情
     */
    public static function QuertDataId($data)
    {
        $reg1 = "/<dd class=\"kyx-pop-.*?\">.*?<\/dd>/";
        $datam = str_replace(array("\r\n", "   ", "\r", "\n", "	"), "", $data);
        preg_match_all($reg1, $datam, $array_data);
        $data_arr = [];
        foreach ($array_data[0] as $v) {
            $vs = str_replace(array('<dd class="kyx-pop-col2">', '<dd class="kyx-pop-col1">', '</dd>', '<span class="line"><label class="left-title">', '：</label>'), "", $v);
            $vs = str_replace(array('</span></span>'), "</span>", $vs);
            $avr = explode('<span ', $vs);
            $reg2 = "/<span class=\"right-text.*?\">.*?<\/span>/";
            preg_match_all($reg2, $vs, $vsr);
            $data_arr = array_merge($data_arr, [$avr[0] => $vsr[0][0]]);
        }
        foreach ($data_arr as $k => $v) {
            if ($k == '商品名称') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $name = $vs;
            }

            if ($k == '商品类型') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $type = $vs;
            }

            if ($k == '购买金额') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $price = $vs;
            }

            if ($k == '订单状态') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $state = $vs;
            }

            if ($k == '购买数量') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $num = $vs;
            }
            if ($k == '购买时间') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $addtime = $vs;
            }
            if ($k == '处理时间') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $endtime = $vs;
            }

            if ($k == '充值信息') {
                $vs = str_replace(array('<span class="right-text">', '</span>'), "", $v);
                $result = $vs;
            }

            if ($k == '处理进度') {
                $vs = str_replace(array('<span class="right-text">', '</span>', '<input type="text" style="width:80px;" class="kyx-pop-txt1 kyx-pop-col-txt" readonly="readonly" value="', '">', '"/>'), "", $v);
                $schedule = $vs;
            }

            if ($k == '退款') {
                $vs = str_replace(array('<span class="right-text" id="backMoneyshow">', '</span>'), "", $v);
                $refund = $vs;
            }
        }
        return [
            'code' => 1,
            'msg' => '数据获取成功',
            'data' => [
                'name' => ($name == '' ? '' : $name),
                'type' => ($type == '' ? '' : $type),
                'price' => ($price == '' ? '' : $price),
                'state' => ($state == '' ? '' : $state),
                'num' => ($num == '' ? '' : $num),
                'addtime' => ($addtime == '' ? '' : $addtime),
                'endtime' => ($endtime == '' ? '' : $endtime),
                'result' => ($result == '' ? '' : $result),
                'schedule' => ($schedule == '' ? '' : $schedule),
                'refund' => ($refund == '' ? '' : $refund),
            ]
        ];
    }

    /**
     * @param $data
     * @param $url
     * 将商品详情页转换为数组
     */
    public static function GoodsDetailsArray($data, $url)
    {
        $reg1 = "/<form.*?>.*?<\/form>/";
        $datam = str_replace(array("\r\n", "\r", "\n", "	"), "", $data);
        preg_match_all($reg1, $datam, $array_data);
        $array_data = $array_data['0'][0];
        $docsreg = "/<div class=\"content\">.*?<\/div>/";
        preg_match_all($docsreg, $datam, $docs);
        $docs = $docs[0][0];
        preg_match_all("/(?:>)(.*)(?:<)/i", $docs, $docs);
        $docs = ($docs[1][0] == '' ? '没有商品说明' : $docs[1][0]);


        $array_dataory = explode('value="', $array_data);

        $goodsId = '';
        $mainKey = '';

        foreach ($array_dataory as $value) {
            if (strpos($value, 'name="goodsId"') !== false) {
                $arr = explode('"', $value);
                $goodsId = $arr[0];
            }
            if (strpos($value, 'name="mainKey"') !== false) {
                $arr = explode('"', $value);
                $mainKey = $arr[0];
            }
        }

        $reg2 = "/<td .*?>.*?<\/td>/";
        preg_match_all($reg2, $array_data, $array_data);
        $data_arr = [];
        foreach ($array_data[0] as $v) {
            if ($v == '<td class="td-line"></td>' || $v == '<td class="td-left"></td>') continue;
            $data_arr = array_merge($data_arr, [$v]);
        }
        $array_data = $data_arr;
        $array_name = $array_data[1];
        preg_match_all("/(?:>)(.*)(?:<)/i", $array_name, $array_name);
        $array_name = $array_name[1][0];

        $array_type = $array_data[3];
        preg_match_all("/(?:>)(.*)(?:<)/i", $array_type, $array_type);
        $array_type = $array_type[1][0];

        $sumprice = 0;
        $price = 0;
        $accountName = [];
        $temptypeName0 = [];
        $temptypeName1 = [];
        $temptypeName2 = [];
        $temptypeName3 = [];
        $temptypeName4 = [];
        $temptypeName5 = [];
        $temptypeName6 = [];
        $temptypeName7 = [];
        $temptypeName8 = [];
        $arr_value = [];
        $arr_arguments = [];

        foreach ($array_data as $v) {

            if (strpos($v, 'id="sumprice"') !== false) {
                $sumprice = 1;
            }

            if (strpos($v, '库存不足,请联系站长补货') !== false) {
                return ['code' => -1, 'msg' => '商品库存不足,请联系站长补货！'];
            }

            if (strpos($v, 'id="accountName"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $accountName);
                $accountName = $accountName[1][0];
                $arr = explode('<input', $accountName);

                $arr[0] = str_replace("：", "", $arr[0]);
                $arr_value = array_merge($arr_value, [$arr[0]]);
                $arr_arguments = array_merge($arr_arguments, ['textAccountName']);
            }

            if (strpos($v, 'id="temptypeName0"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName0);
                $temptypeName0 = $temptypeName0[1][0];
                $arr = explode('>', $temptypeName0);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName0']);
            }

            if (strpos($v, 'id="temptypeName1"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName1);
                $temptypeName1 = $temptypeName1[1][0];
                $arr = explode('>', $temptypeName1);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName1']);
            }

            if (strpos($v, 'id="temptypeName2"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName2);
                $temptypeName2 = $temptypeName2[1][0];
                $arr = explode('>', $temptypeName2);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName2']);
            }

            if (strpos($v, 'id="temptypeName3"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName3);
                $temptypeName3 = $temptypeName3[1][0];
                $arr = explode('>', $temptypeName3);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName3']);
            }

            if (strpos($v, 'id="temptypeName4"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName4);
                $temptypeName4 = $temptypeName4[1][0];
                $arr = explode('>', $temptypeName4);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName4']);
            }

            if (strpos($v, 'id="temptypeName5"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName5);
                $temptypeName5 = $temptypeName5[1][0];
                $arr = explode('>', $temptypeName5);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName5']);
            }

            if (strpos($v, 'id="temptypeName6"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName6);
                $temptypeName6 = $temptypeName6[1][0];
                $arr = explode('>', $temptypeName6);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName6']);
            }

            if (strpos($v, 'id="temptypeName7"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName7);
                $temptypeName7 = $temptypeName7[1][0];
                $arr = explode('>', $temptypeName7);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName7']);
            }

            if (strpos($v, 'id="temptypeName8"') !== false) {
                preg_match_all("/(?:>)(.*)(?:<)/i", $v, $temptypeName8);
                $temptypeName8 = $temptypeName8[1][0];
                $arr = explode('>', $temptypeName8);

                $arr[1] = str_replace("：", "", $arr[1]);
                $arr_value = array_merge($arr_value, [$arr[1]]);
                $arr_arguments = array_merge($arr_arguments, ['lblName8']);
            }

            if (strpos($v, 'id="saleprice"') !== false) {
                $arr = explode('value="', $v);
                $arr = explode('"/>', $arr[1]);
                $price = $arr[0];
            }
            /*if (strpos($v, 'id="messinfo"') !== false) {
                $arr_value = array_merge($arr_value, ['购买备注']);
                $arr_arguments = array_merge($arr_arguments, ['messinfo']);
            }*/
        }
        if ($goodsId == '') {
            return [
                'code' => -4,
                'msg' => '商品详情查询失败,部分卡易信商品是无法查询的,已经<font color="red">暂停销售</font>的商品等！',
                'data' => [
                    'price' => (float)$price
                ]
            ];
        }

        if ($array_type == '提取卡密') {
            return [
                'code' => -1,
                'msg' => '此商品需要手动提卡！<br>点击<a href=\'' . $url . '\' target=\'_blank\'>确定</a>打开提卡界面<hr>商品名称：' . $array_name . '<br>商品售价：<font color=red>' . $price . '元1张卡</font><br>商品说明：' . $docs,
            ];
        }

        return [
            'code' => 1,
            'msg' => '商品数据获取成功',
            'data' => [
                'gid' => (float)$goodsId,
                'mainKey' => $mainKey,
                'name' => $array_name,
                'type' => $array_type,
                'min' => $sumprice,
                'max' => 10000000,
                'price' => (float)$price,
                'inputs' => $arr_value,
                'pipei' => $arr_arguments,
                'content' => $docs,
                'url' => $url,
            ]
        ];
    }

    /**
     * @param $url
     * @param $data
     * @param $mid
     * @return array
     * 商品列表页码转换
     */
    public static function GoodsListArray($url, $data, $mid)
    {
        $reg1 = "/<a .*?>.*?<\/a>/";
        $reg2 = "/<font .*?>.*?<\/font>/";
        $reg4 = "/<strong.*?>.*?<\/strong>/";
        $reg5 = "/<td .*?>.*?<\/td>/";
        $datam = str_replace(array("\r\n", "\r", "\n", "	", " "), "", $data);
        $aarray = [];
        $aarray2 = [];
        $moenys = [];
        $kucun = [];
        preg_match_all($reg1, $data, $aarray);
        preg_match_all($reg2, $data, $aarray2);
        preg_match_all($reg4, $datam, $moenys);
        preg_match_all($reg5, $data, $kucun);
        $array_a = [];
        foreach ($aarray[0] as $v) {
            if (strpos($v, 'addgoodsfavorite(') !== false) continue;
            $array_a = array_merge($array_a, [$v]);
        }
        $reg3 = "/onclick=\"([^\"]+)/";

        $shop_url = [];
        for ($i = 0; $i < count($array_a); $i++) {
            preg_match_all($reg3, $array_a[$i], $hrefarray);
            $url_arr = explode(',', $hrefarray[1][0]);
            $urlrs = str_replace("'", "", $url_arr[0]);
            $urlrs = str_replace("OpenTemplate(", $url . 'front/inter/', $urlrs);
            $urlrs = $urlrs . '&dirId=' . $mid;
            $shop_url = array_merge($shop_url, [$urlrs]);
        }

        $name_arr = [];
        for ($i = 0; $i < count($aarray2[0]); $i++) {
            $namer = explode('>', $aarray2[0][$i]);
            $name = str_replace("</font", "", $namer[1]);
            $name_arr = array_merge($name_arr, [$name]);
        }
        $datart = [];
        $r = 0;
        foreach ($shop_url as $v) {
            $money = str_replace("<strong>", "", $moenys[0][$r]);
            $money = str_replace("</strong>", "", $money);
            preg_match_all("/(?:>)(.*)(?:<)/i", $kucun[0][$r], $kuc);
            $datart[] = ['name' => $name_arr[$r], 'url' => $v, 'money' => $money . '元', 'Inventory' => $kuc[1][0]];
            $r++;
        }
        return $datart;
    }

    /**
     * @param $HtmlData
     * 将卡易信目录转换为数组格式！
     */
    public static function CatalogueArray($HtmlData)
    {
        $reg1 = "/<a .*?>.*?<\/a>/";
        $aarray = [];
        preg_match_all($reg1, $HtmlData, $aarray);
        $hrefarray = [];
        $acontent = [];
        $reg2 = "/href=\"([^\"]+)/";
        $data_mulu = [];
        for ($i = 0; $i < count($aarray[0]); $i++) {
            preg_match_all($reg2, $aarray[0][$i], $hrefarray);
            if (strpos($hrefarray[1][0], 'front/inter/goodSearchDir.htm?dirId=,0,0') !== false || $hrefarray[1][0] == '') continue;
            $idarray = explode('=', $hrefarray[1][0]);
            $idarray = $idarray[1];
            if ($idarray == '') continue;
            $reg3 = "/>(.*)<\/a>/";
            preg_match_all($reg3, $aarray[0][$i], $acontent);
            if ($acontent[1][0] == '') continue;
            $data_mulu[] = ['name' => $acontent[1][0], 'url' => $hrefarray[1][0], 'id' => $idarray];
        }
        return $data_mulu;
    }

}